﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XYTXL.AppCode;
using System.Data;
using XYTXL.Data;

namespace XYTXL.View.Comon
{
    public partial class CommonMangner : BasePage
    {


        public string strFormCode
        {

            get { return Request.QueryString["FormCode"] ?? ""; }
        }
        public string strFormID
        {
            get { return Request.QueryString["FormID"] ?? "0"; }
        }
        public string MangnerType
        {
            get { return Request.QueryString["MangnerType"] ?? "YCL"; }
        }
        public FormUControl WFForm
        {

            get { return UserControl.Controls[0] as FormUControl; }
        }
        public JH_Auth_FormBase FormBaseData
        {
            get
            {
                return ViewState[hidFormCode.Value] == null ? new FormHelp().GetFormCodeByFormCode(hidFormCode.Value) : (JH_Auth_FormBase)ViewState[hidFormCode.Value];
            }
            set
            {
                ViewState[hidFormCode.Value] = value;
            }
        }
        protected override void OnInit(EventArgs e)
        {
            try
            {
                hidFormCode.Value = strFormCode;
                hidFormID.Value = strFormID;
                //加载用户控件
                FormUControl Control = LoadControl("/View/UCMangForm/" + FormBaseData.FormViewUrl) as FormUControl;
                UserControl.Controls.Add(Control);
                base.OnInit(e);
                //为用户控件加载用户数据
                Control.UserInfo = UserInfo;
                lblTitle.Text = FormBaseData.FormDec;
                if (!IsPostBack)
                {
                    hidConfirmUsers.Value = new FormHelp().GetConfirmUsers(hidFormCode.Value + strFormID);
                    Control.initALLForm(hidFormCode.Value);
                    Control.initMangerForm(int.Parse(strFormID), "VIEW");
                }

                if (MangnerType != "dcl")
                {
                    tabSP.Visible = false;
                } 

                btManageForm.Attributes.Add("onclick", "this.value='正在提交中,請稍等……';this.disabled=true;" + this.GetPostBackEventReference(btManageForm) + ";");
            }
            catch (Exception)
            {

                throw;
            }

        }

        protected void btRebackForm_Click(object sender, EventArgs e)
        {
            btRebackForm.Enabled = false;
            btManageForm.Enabled = false;
            WFForm.RebackForm(int.Parse(strFormID), txtFormYJ.Value);
            AlertMSG("3", "操作成功,此表单已退回");
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscriptsuc", "<script>AddSuccess()</script>");

        }

        protected void btManageForm_Click(object sender, EventArgs e)
        {
            btRebackForm.Enabled = false;
            btManageForm.Enabled = false;
            WFForm.SPForm(int.Parse(strFormID), txtFormYJ.Value);
            AlertMSG("3", " 操作成功，此表单已审批通过");
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscriptsuc", "<script>AddSuccess()</script>");

        }
    }
}